﻿using Api.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PushTask
{
    class Program
    {
        static void Main(string[] args)
        {
            //注册 當前程序未處理異常事件
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(currAppdomain_UnhandledException);

            if (args.Count() == 0)
            {
                LogHelper.WriteCreateNewLog("error", "请输入参数 StartApple");
            }

            string cmd = args[0].Trim();

            switch (cmd.ToLower())
            {
                case "push":
                    while (true)
                    {
                        //為了保證每次循環都獲取到數據庫中最新的數據
                        Push.Send();
                        Thread.Sleep(3000);
                    }
                case "signalr":
                    while (true)
                    {
                        //為了保證每次循環都獲取到數據庫中最新的數據
                        SignalrPush.Send();
                        Thread.Sleep(3000);
                    }
                case "datatransfer":
                    break;
            }
        }



        #region 當前程序未處理異常事件
        /// <summary>
        /// 當前程序未處理異常事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void currAppdomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            LogHelper.WriteCreateNewLog("error", e?.ExceptionObject.ToString());
            Environment.Exit(0);
        }
        #endregion
    }
}
